package com.apes.scm.stock.inventory.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.stock.inventory.model.InventoryList;
import com.apes.scm.stock.inventory.model.InventoryListItem;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Set;

public interface InventoryListItemRepository extends CustomRepository<InventoryListItem, String>{
    @Modifying
    @Query(value = "UPDATE STO_INVENTORY_LIST_ITEM SET PROFIT_AND_LOSS = COUNT_QUANTITY - CUSTODY_QTY WHERE INVENTORY_LIST_ID = ?1 AND COUNT_QUANTITY <> CUSTODY_QTY",
           nativeQuery = true)
    void updateInventoryListItem(String id);

    @Query("SELECT T FROM InventoryListItem T WHERE T.custodyQty <> T.countQuantity AND T.inventoryListId = :id")
    Set<InventoryListItem> qryInventoryDiffCompound(@Param("id")InventoryList id);
}
